﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.ComponentModel;
using System.Xml;



namespace Machop
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private DatabaseConnection dbConnection;
        private bool nuevo;
        private DataTable dt;
        
        private int currentId;
        private Dictionary<int, string> dataDictionary;

        public MainWindow()
        {
            InitializeComponent();



        }



        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            dataDictionary = new Dictionary<int, string>();
            dbConnection = new DatabaseConnection("127.0.0.1", "5432", "postgres", "root", "machop");
            loadObreros();
            loadAreas();
            loadCentros();
            loadBancos();
            loadCuentas();
            loadHorarios();
            loadFeriados();
            loadExtras();

            reportesFechaIncialDP.SelectedDate = System.DateTime.Now.Date;
            reportesFechaFinalDP.SelectedDate = System.DateTime.Now.Date;
        }

        private bool loadDbConnectionSettings()
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load("dbconfig.xml");

            return true;
        }

        #region Loads
        private void loadObreros()
        {
            dt = dbConnection.SendQuery(@"SELECT Obrero.nombre AS nombre, fechaNacimiento AS fechan, nombrearea as Area, HoraEntrada, HoraSalida 
                                            FROM Obrero, Horario, Area 
                                            WHERE Horario.idhorario = Obrero.idhorario AND Area.idArea = Obrero.idArea AND Obrero.activo = true");
            obrerosDataGrid.ItemsSource = dt.DefaultView;

            
        }

        private void loadAreas()
        {
            dt = dbConnection.SendQuery(@"SELECT idArea as ID, nombreArea as Nombre, nombrecentrocosto AS Centro FROM Area, CentroDeCosto WHERE Area.idcentrocosto = CentroDeCosto.idcentrocosto AND Area.activo = true ");
            areasDataGrid.ItemsSource = dt.DefaultView;

            obrerosAreaCB.ItemsSource = areasDataGrid.ItemsSource;
            obrerosAreaCB.DisplayMemberPath = @"nombre";
        }

        private void loadCentros()
        {
            dt = dbConnection.SendQuery(@"SELECT idCentroCosto as id, nombreCentroCosto as Nombre FROM CentroDeCosto  WHERE activo = true");
            centrosDataGrid.ItemsSource = dt.DefaultView;
            

            //Set areasCentro combobox source
            areasCentroCB.ItemsSource = centrosDataGrid.ItemsSource;
            areasCentroCB.DisplayMemberPath = @"nombre";
           
        }

        private void loadBancos()
        {
            dt = dbConnection.SendQuery(@"SELECT idBanco AS ID, nombreBanco AS Nombre FROM Banco WHERE activo = true");
            bancosDataGrid.ItemsSource = dt.DefaultView;

            cuentasBancoCB.ItemsSource = bancosDataGrid.ItemsSource;
            cuentasBancoCB.DisplayMemberPath = @"nombre";
        }

        private void loadCuentas()
        {
            dt = dbConnection.SendQuery(@"SELECT noCuenta, monto, nombreBanco as banco FROM Cuenta, Banco");
            cuentasDataGrid.ItemsSource = dt.DefaultView;
        }

        private void loadHorarios()
        {
            dt = dbConnection.SendQuery(@"SELECT horaEntrada AS horaEntrada, horaSalida AS horaSalida, costo AS costo FROM Horario AS Horario");
            horariosDataGrid.ItemsSource = dt.DefaultView;

            obrerosHorarioCB.ItemsSource = horariosDataGrid.ItemsSource;
            obrerosHorarioCB.DisplayMemberPath = @"horaentrada";

            obrerosHorarioCB2.ItemsSource = horariosDataGrid.ItemsSource;
            obrerosHorarioCB2.DisplayMemberPath = @"horasalida";
        }

        private void loadFeriados()
        {
            dt = dbConnection.SendQuery(@"SELECT * FROM Feriado AS Feriado(fecha, descripcion)");
            feriadosDataGrid.ItemsSource = dt.DefaultView;
        }

        private void loadExtras()
        {
            dt = dbConnection.SendQuery(@"SELECT * FROM HorasExtra AS HorasExtra(id, costo)");
            extrasDataGrid.ItemsSource = dt.DefaultView;
        }

        #endregion Loads

        private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
        }

        private void tabControl2_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
        }

        #region Centros
        private void centrosDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //textBox1.Text = ((DataRowView)centrosDataGrid.CurrentCell.Item).Row.ItemArray[0].ToString();
            try
            {
                centrosNombreTF.Text = ((DataRowView)centrosDataGrid.CurrentCell.Item).Row.Field<string>(@"nombre").ToString();                
                currentId = ((DataRowView)centrosDataGrid.CurrentCell.Item).Row.Field<int>(@"id");

            }
            catch (InvalidCastException ice) { };
        }

        private void centrosModificarBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = false;
            centrosEnableForm();
        }

        private void centrosNuevoBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = true;
            centrosClearForm();
            centrosEnableForm();
        }

        private void centrosGuardarBT_Click(object sender, RoutedEventArgs e)
        {
            if (nuevo)
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM agregarCentroCosto('{0}')", 
                    centrosNombreTF.Text));
            }
            else
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM modificarCentroCosto({0}, '{1}')", 
                    currentId, centrosNombreTF.Text));

            }

            loadCentros();
            centrosDisableForm();
            centrosClearForm();
        }

        private void centrosEliminarBT_Click(object sender, RoutedEventArgs e)
        {

            dbConnection.SendQuery(
                    string.Format("SELECT * FROM eliminarCentroCosto({0})",
                    currentId));
            loadCentros();
            centrosDisableForm();
            centrosClearForm();
        }

        private void centrosClearForm()
        {
            centrosNombreTF.Text = string.Empty;
        }

        private void centrosEnableForm()
        {
            centrosNombreTF.IsEnabled = true;
            centrosGuardarBT.IsEnabled = true;
        }

        private void centrosDisableForm()
        {
            centrosNombreTF.IsEnabled = false;
            centrosGuardarBT.IsEnabled = false;
        }

        #endregion Centros

        #region Areas
        private void areasDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                areasNombreTF.Text = ((DataRowView)areasDataGrid.CurrentCell.Item).Row.Field<string>(@"nombre").ToString();
                currentId = ((DataRowView)areasDataGrid.CurrentCell.Item).Row.Field<int>(@"id");
                //No sirve
                areasCentroCB.SelectedIndex = areasCentroCB.Items.IndexOf(((DataRowView)areasDataGrid.CurrentCell.Item).Row.Field<string>(@"centro"));


            }
            catch (InvalidCastException ice) { };
        }

        private void areasNuevoBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = true;
            areasClearForm();
            areasEnableForm();
        }

        private void areasModificarBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = false;
            areasEnableForm();
        }

        private void areasGuardarBT_Click(object sender, RoutedEventArgs e)
        {
            if (nuevo)
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM agregarArea('{0}', {1})",
                    areasNombreTF.Text, ((DataRowView)centrosDataGrid.Items[areasCentroCB.SelectedIndex]).Row.Field<int>(@"id")));
    
            }
            else
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM modificarArea({0}, '{1}', {2})",
                    currentId, areasNombreTF.Text, ((DataRowView)centrosDataGrid.Items[areasCentroCB.SelectedIndex]).Row.Field<int>(@"id")));

            }

            loadAreas();
            areasClearForm();
            areasDisableForm();
        }

        private void areasEliminarBT_Click(object sender, RoutedEventArgs e)
        {
            dbConnection.SendQuery(
                string.Format("SELECT * FROM eliminarArea({0})",
                        currentId));
            loadAreas();
            areasClearForm();
            areasDisableForm();
        }

        private void areasClearForm()
        {
            areasNombreTF.Text = string.Empty;
            areasCentroCB.SelectedIndex = -1;
        }

        private void areasEnableForm()
        {
            areasNombreTF.IsEnabled = true;
            areasCentroCB.IsEnabled = true;
            areasGuardarBT.IsEnabled = true;
        }

        private void areasDisableForm()
        {
            areasNombreTF.IsEnabled = false;
            areasCentroCB.IsEnabled = false;
            areasGuardarBT.IsEnabled = false;
        }

        #endregion Areas

        #region Bancos
        private void bancosDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                bancosNombreTF.Text = ((DataRowView)bancosDataGrid.CurrentCell.Item).Row.Field<string>(@"nombre").ToString();
                currentId = ((DataRowView)bancosDataGrid.CurrentCell.Item).Row.Field<int>(@"id");

            }
            catch (InvalidCastException ice) { };
        }

        private void bancosNuevoBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = true;
            bancosClearForm();
            bancosEnableForm();
        }

        private void BancosModificarBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = false;
            bancosEnableForm();
        }

        private void bancosEliminarBT_Click(object sender, RoutedEventArgs e)
        {

        }

        private void BancosGuardarBT_Click(object sender, RoutedEventArgs e)
        {
            if (nuevo)
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM agregarBanco('{0}')",
                    bancosNombreTF.Text));
            }
            else
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM modificarBanco({0}, '{1}')",
                    currentId, bancosNombreTF.Text));

            }

            loadBancos();
            bancosDisableForm();
            bancosClearForm();
        }


        private void bancosClearForm()
        {
            bancosNombreTF.Text = string.Empty;
        }

        private void bancosEnableForm()
        {
            bancosNombreTF.IsEnabled = true;
            bancosGuardarBT.IsEnabled = true;
        }

        private void bancosDisableForm()
        {
            bancosNombreTF.IsEnabled = false;
            bancosGuardarBT.IsEnabled = false;
        }

        #endregion Bancos

        #region Cuentas
        private void cuentasDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                cuentasNoTF.Text = ((DataRowView)cuentasDataGrid.CurrentCell.Item).Row.Field<string>(@"nocuenta").ToString();
                currentId = int.Parse(cuentasNoTF.Text);
                cuentasMontoTF.Text = ((DataRowView)cuentasDataGrid.CurrentCell.Item).Row.Field<decimal>(@"monto").ToString();
                //No sirve
                cuentasBancoCB.SelectedIndex = areasCentroCB.Items.IndexOf(((DataRowView)cuentasDataGrid.CurrentCell.Item).Row.Field<string>(@"banco"));


            }
            catch (InvalidCastException ice) { };
        }

        private void cuentasNuevoBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = true;
            cuentasClearForm();
            cuentasEnableForm();
            
        }

        private void cuentasModificarBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = false;
            cuentasEnableForm();
        }

        private void cuentasEliminarBT_Click(object sender, RoutedEventArgs e)
        {

        }

        private void cuentasGuardarBT_Click(object sender, RoutedEventArgs e)
        {
            if (nuevo)
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM agregarCuenta('{0}', {1}, {2})",
                    cuentasNoTF.Text, cuentasMontoTF.Text, ((DataRowView)bancosDataGrid.Items[cuentasBancoCB.SelectedIndex]).Row.Field<int>(@"id")));

            }
            else
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM modificarCuenta('{0}', {1}, {2})",
                    cuentasNoTF.Text, cuentasMontoTF.Text, ((DataRowView)bancosDataGrid.Items[cuentasBancoCB.SelectedIndex]).Row.Field<int>(@"id")));

            }

            loadCuentas();
            cuentasClearForm();
            cuentasDisableForm();
        }

        private void cuentasClearForm()
        {
            cuentasNoTF.Text = string.Empty;
            cuentasMontoTF.Text = string.Empty;
            cuentasBancoCB.SelectedIndex = -1;
        }

        private void cuentasEnableForm()
        {
            cuentasNoTF.IsEnabled = true;
            cuentasMontoTF.IsEnabled = true;
            cuentasBancoCB.IsEnabled = true;
            cuentasGuardarBT.IsEnabled = true;
        }

        private void cuentasDisableForm()
        {
            cuentasNoTF.IsEnabled = false;
            cuentasMontoTF.IsEnabled = false;
            cuentasBancoCB.IsEnabled = false;
            cuentasGuardarBT.IsEnabled = false;
        }

        #endregion Cuentas


        #region Obreros
        private void obrerosDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                obrerosNombreTF.Text = ((DataRowView)obrerosDataGrid.CurrentCell.Item).Row.Field<string>(@"nombre").ToString();
                currentId = ((DataRowView)obrerosDataGrid.CurrentCell.Item).Row.Field<int>(@"id");
                obrerosFechanDP.SelectedDate = DateTime.Parse(((DataRowView)obrerosDataGrid.CurrentCell.Item).Row.Field<string>(@"fechan").ToString());
                
                //No sirve
                //cuentasBancoCB.SelectedIndex = areasCentroCB.Items.IndexOf(((DataRowView)cuentasDataGrid.CurrentCell.Item).Row.Field<string>(@"banco"));


            }
            catch (InvalidCastException ice) { };
        }


        private void obrerosNuevoBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = true;
            obrerosClearForm();
            obrerosEnableForm();
        }

        private void obrerosModificarBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = false;
            obrerosEnableForm();
        }

        private void obrerosGuardarBT_Click(object sender, RoutedEventArgs e)
        {
            // MyString = MyDateTime.ToString("yyyy-MM-dd HH:mm tt"
            
            if (nuevo)
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM agregarObrero('{0}', {1}, '{2}', {3})",
                    obrerosNombreTF.Text, 
                    ((DataRowView)areasDataGrid.Items[obrerosAreaCB.SelectedIndex]).Row.Field<int>(@"id"),
                    obrerosFechanDP.SelectedDate.ToString(),
                    ((DataRowView)horariosDataGrid.Items[obrerosHorarioCB.SelectedIndex]).Row.Field<int>(@"id")));
                
            }
            else
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM modificarObrero({0}, '{1}', {2}, '{3}', {4})",
                    currentId, 
                    obrerosNombreTF.Text,
                    ((DataRowView)areasDataGrid.Items[obrerosAreaCB.SelectedIndex]).Row.Field<int>(@"id"),
                    obrerosFechanDP.SelectedDate.ToString(),
                    ((DataRowView)horariosDataGrid.Items[obrerosHorarioCB.SelectedIndex]).Row.Field<int>(@"id")));
            }

            loadObreros();
            obrerosClearForm();
            obrerosDisableForm();
        }


        private void obrerosHorarioCB_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            obrerosHorarioCB2.SelectedIndex = obrerosHorarioCB.SelectedIndex;
        }

        private void obrerosEliminarBT_Click(object sender, RoutedEventArgs e)
        {
            dbConnection.SendQuery(
                    string.Format("SELECT * FROM eliminarObrero({0})",
                    currentId));

            loadObreros();
            obrerosClearForm();
            obrerosDisableForm();
        }

        private void obrerosClearForm()
        {
            obrerosNombreTF.Text = string.Empty;

            obrerosAreaCB.SelectedIndex = -1;
            obrerosHorarioCB.SelectedIndex = -1;
        }

        private void obrerosEnableForm()
        {
            obrerosNombreTF.IsEnabled = true;
            obrerosAreaCB.IsEnabled = true;
            obrerosFechanDP.IsEnabled = true;
            obrerosHorarioCB.IsEnabled = true;
        }

        private void obrerosDisableForm()
        {
            obrerosNombreTF.IsEnabled = false;
            obrerosAreaCB.IsEnabled = false;
            obrerosFechanDP.IsEnabled = false;
            obrerosHorarioCB.IsEnabled = false;
        }


        #endregion Obreros

        #region Horarios
        private void horariosDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                horariosEntradaTF.Text = ((DataRowView)horariosDataGrid.CurrentCell.Item).Row.Field<DateTime>(@"horaentrada").TimeOfDay.ToString();
                horariosSalidaTF.Text = ((DataRowView)horariosDataGrid.CurrentCell.Item).Row.Field<DateTime>(@"horasalida").TimeOfDay.ToString();
                horariosCostoTF.Text =  ((DataRowView)horariosDataGrid.CurrentCell.Item).Row.Field<decimal>(@"costo").ToString();
                currentId = ((DataRowView)areasDataGrid.CurrentCell.Item).Row.Field<int>(@"id");
                //No sirve
            }
            catch (InvalidCastException ice) { };
        }

        private void horariosNuevoBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = true;
            horariosClearForm();
            horariosEnableForm();
        }

        private void horariosModificarBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = false;
            horariosEnableForm();
        }

        private void horariosEliminarBT_Click(object sender, RoutedEventArgs e)
        {

        }

        private void horariosGuardarBT_Click(object sender, RoutedEventArgs e)
        {
            if (nuevo)
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM agregarHorario('{0}', '{1}', {2})",
                    horariosEntradaTF.Text, horariosSalidaTF.Text, horariosCostoTF.Text));

            }
            else
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM modificarHorario('{0}', '{1}', '{2}', {3})",
                    currentId, horariosEntradaTF.Text, horariosSalidaTF.Text, horariosCostoTF.Text));

            }

            loadHorarios();
            horariosClearForm();
            horariosDisableForm();
        }

        private void horariosClearForm()
        {
            horariosEntradaTF.Text = string.Empty;
            horariosSalidaTF.Text = string.Empty;
            horariosCostoTF.Text = string.Empty;
        }

        private void horariosEnableForm()
        {
            horariosEntradaTF.IsEnabled = true;
            horariosSalidaTF.IsEnabled = true;
            horariosCostoTF.IsEnabled = true;
            horariosGuardarBT.IsEnabled = true;
        }

        private void horariosDisableForm()
        {
            horariosEntradaTF.IsEnabled = false;
            horariosSalidaTF.IsEnabled = false;
            horariosCostoTF.IsEnabled = false;
            horariosGuardarBT.IsEnabled = false;

        }

        #endregion Horarios



        #region Feriados

        private void feriadosDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                feriadosFechaDP.SelectedDate = ((DataRowView)feriadosDataGrid.CurrentCell.Item).Row.Field<DateTime>(@"fecha");
                       

            }
            catch (InvalidCastException ice) { };
        }

        private void feriadosClearForm()
        {
            feriadosDescripcionTF.Text = string.Empty;
        }

        private void feriadosEnableForm()
        {
            feriadosFechaDP.IsEnabled = true;
            feriadosGuardarBT.IsEnabled = true;
            feriadosDescripcionTF.IsEnabled = true;
        }

        private void feriadosDisableForm()
        {
            feriadosFechaDP.IsEnabled = false;
            feriadosDescripcionTF.IsEnabled = false;
            feriadosGuardarBT.IsEnabled = false;
        }

        private void feriadosNuevoBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = true;
            feriadosClearForm();
            feriadosEnableForm();
        }

        private void feriadosModificarBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = false;
            feriadosEnableForm();
        }

        private void feriadosEliminarBT_Click(object sender, RoutedEventArgs e)
        {

        }

        private void feriadosGuardarBT_Click(object sender, RoutedEventArgs e)
        {
            if (nuevo)
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM agregarFeriado('{0}', '{1}')",
                    feriadosFechaDP.SelectedDate.ToString(),
                    feriadosDescripcionTF.Text));

            }
            else
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM modificarFeriado('{0}', '{1}')",
                    feriadosFechaDP.SelectedDate.ToString(),
                    feriadosDescripcionTF.Text));
            }

            loadFeriados();
            feriadosClearForm();
            feriadosDisableForm();
        }

        #endregion Feriados

        #region Extras

        private void extrasDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }


        private void extrasClearForm()
        {
            extrasCostoTF.Text = string.Empty;
        }

        private void extrasEnableForm()
        {
            extrasCostoTF.IsEnabled = true;
            extrasGuardarBT.IsEnabled = true;

        }

        private void extrasDisableForm()
        {
            extrasCostoTF.IsEnabled = false;
            extrasGuardarBT.IsEnabled = false;
        }

        private void extrasModificarBT_Click(object sender, RoutedEventArgs e)
        {
            nuevo = false;
            feriadosEnableForm();
        }

        private void extrasGuardarBT_Click(object sender, RoutedEventArgs e)
        {
            if (nuevo)
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM agregarHoraExtra('{0}', '{1}')",
                    feriadosFechaDP.SelectedDate.ToString(),
                    feriadosDescripcionTF.Text));

            }
            else
            {
                dbConnection.SendQuery(
                    string.Format("SELECT * FROM modificarFeriado('{0}', '{1}')",
                    feriadosFechaDP.SelectedDate.ToString(),
                    feriadosDescripcionTF.Text));
            }

            loadFeriados();
            feriadosClearForm();
            feriadosDisableForm();
        }

        #endregion Extras


        private void loadReporte()
        {
            reportesDataGrid.ItemsSource = dt.DefaultView;
        }

        private void reportesCumplesBT_Click(object sender, RoutedEventArgs e)
        {
            dt = dbConnection.SendQuery(
                string.Format("SELECT * FROM cumpleanerosSemana"));
            
            loadReporte();
        }

        private void reportesTardanzasBT_Click(object sender, RoutedEventArgs e)
        {
            dt = dbConnection.SendQuery(
                string.Format("SELECT * FROM tardanzas('{0}', '{1}') AS (id integer, Nombre varchar, Fecha date, minsRetraso integer)",
                reportesFechaIncialDP.SelectedDate.ToString(),
                reportesFechaFinalDP.SelectedDate.ToString()));

            loadReporte();
        }

        private void reportesMinutosBT_Click(object sender, RoutedEventArgs e)
        {
            dt = dbConnection.SendQuery(
                string.Format("SELECT * FROM minutosAcumulados('{0}', '{1}') AS (idArea integer, nombreArea varchar, idObrero integer, nombre varchar, minutos integer)",
                reportesFechaIncialDP.SelectedDate,
                reportesFechaFinalDP.SelectedDate));

            loadReporte();
        }

        private void obrerosResponsables_Click(object sender, RoutedEventArgs e)
        {
            dt = dbConnection.SendQuery(
                string.Format("SELECT * FROM obrerosResponsables('{0}', '{1}') AS (IdArea integer, NombreArea varchar, idObrero integer, nombre varchar)",
                reportesFechaIncialDP.SelectedDate,
                reportesFechaFinalDP.SelectedDate));

            loadReporte();
        }

        private void pagosPersonalBT_Click(object sender, RoutedEventArgs e)
        {
            dt = dbConnection.SendQuery(
                string.Format("SELECT * FROM pagosAlPersonal('{0}', '{1}') AS (idObrero integer, Nombre varchar, FechaInicio date, FechaFin date)",
                reportesFechaIncialDP.SelectedDate,
                reportesFechaFinalDP.SelectedDate));

            loadReporte();
        }





        //idArea, nombreArea, idObrero, ((horasExtra + horasLaborales) * 60)
    }
}
